package xyz.ieden.jpa.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger REST API生成器配置
 * 访问地址：http://localhost:8080/swagger-ui.html
 */
@Configuration
@EnableSwagger2
public class Swagger2Configuration {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                // 当前包的路径
                .apis(RequestHandlerSelectors.basePackage("xyz.ieden.jpa"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 页面标题
                .title("Spring Boot中使用Swagger2构建RESTful APIs")
                // 描述
                .description("SpringBoot JPA 提供的 Rest 服务")
                // 服务条款的 URL
                .termsOfServiceUrl("http://www.ieden.xyz")
                // 作者
                .contact(new Contact("GavinLen", "", ""))
                // 版本
                .version("1.0")
                .build();
    }

}
